/**
 * 将数据库中的法律法规网页文件保存下来 
 */
import { Driver } from "../db";
import * as fs from "fs";

const DriverClass = require("../db");

let opt = new Driver();


let storeFile = function (savePath: string, content: string) {
    fs.writeFileSync(savePath, content);
};

opt.pagnate("laws", {}, 0, 4000).then((rs: any) => {
    rs.forEach((it: any) => {
        console.log('export start!');
        let title: string = it["title"];
        title = title.replace(/\s+/g, "");
        if (title.length > 25)
            title = title.substr(0, 25);
        let dir: string = "./" + it["类型"];
        console.log("dir:" + dir);
        if (!fs.existsSync(dir)) {
            fs.mkdirSync(dir);
        }
        storeFile(dir + "/" + title + ".html", it["网页"]);
        console.log(title + " save successful!");
    });
    process.exit(0);
}, );